﻿using Api.Application.Command.Menu;
using Api.DTO;
using Domain;
using ErrorCode;
using Infrastructure;
using MediatR;

namespace Api.Application.Handler.Menu
{
    public class GetMenuZiHandler : IRequestHandler<GetMenuZiCommand, ApiResult<List<MenuDTO>>>
    {
        private readonly IBase<MenuModel> menuRepo;

        public GetMenuZiHandler(IBase<MenuModel> menuRepo)
        {
            this.menuRepo = menuRepo;
        }
        public Task<ApiResult<List<MenuDTO>>> Handle(GetMenuZiCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuDTO>> result = new ApiResult<List<MenuDTO>>();
            var info = menuRepo.GetAll().Where(x => x.PId == request.Id);
            if (info.Count() > 0)
            {
                result.Code=ApiEnum.OK;
                result.Msg = "有子集";
            }
            else
            {
                result.Code=ApiEnum.Fail;
                result.Msg = "没有子集";
            }
            return Task.FromResult(result);
        }
    }
}
